package com.sdhs.listmanage.controller;


import com.sdhs.common.annotation.Log;
import com.sdhs.common.annotation.RepeatSubmit;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.domain.R;
import com.sdhs.common.core.page.PageQuery;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.validator.group.AddGroup;
import com.sdhs.common.utils.validator.group.EditGroup;
import com.sdhs.listmanage.domain.bo.GcProjectManageListBo;
import com.sdhs.listmanage.domain.vo.GcProjectManageListVo;
import com.sdhs.listmanage.service.IGcProjectManageListService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 项目清单
 *
 * @author may
 * @date 2023-07-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/projectManageList")
public class GcProjectManageListController extends BaseController {

    private final IGcProjectManageListService gcProjectManageListService;

    /**
     * 查询项目清单列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcProjectManageListBo bo, PageQuery pageQuery) {
        return gcProjectManageListService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取项目清单详细信息
     *
     * @param id 主键
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:query')")
    @GetMapping("/{id}")
    public R<GcProjectManageListVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(gcProjectManageListService.queryById(id));
    }

    /**
     * 通过项目ID查询项目清单
     *
     * @param projectId 项目ID
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:query')")
    @GetMapping("/getInfoByProjectId/{projectId}")
    public R<GcProjectManageListVo> getInfoByProjectId(@NotNull(message = "项目ID不能为空") @PathVariable Long projectId) {
        return R.ok(gcProjectManageListService.getInfoByProjectId(projectId));
    }

    /**
     * 新增项目清单
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:add')")
    @Log(title = "项目清单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<GcProjectManageListVo> add(@Validated(AddGroup.class) @RequestBody GcProjectManageListBo bo) {
        return R.ok(gcProjectManageListService.insertByBo(bo));
    }

    /**
     * 修改项目清单
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:edit')")
    @Log(title = "项目清单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<GcProjectManageListVo> edit(@Validated(EditGroup.class) @RequestBody GcProjectManageListBo bo) {
        return R.ok(gcProjectManageListService.updateByBo(bo));
    }

    /**
     * 删除项目清单
     *
     * @param ids 主键串
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:remove')")
    @Log(title = "项目清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(gcProjectManageListService.deleteWithValidByIds(List.of(ids)));
    }
}
